<template>
  <div class="app-container device-time-page">
    <PanelGroup :panel-list="panelGroupList" />
    <div class="display-wrap">
      <h4 class="factory-name">厂区列表</h4>
      <div class="factory-wrap">
        <el-button v-for="(f,index) in factoryList" :key="f.id" :type="activeIndex===index?'primary':''">{{ f.name }}</el-button>
      </div>
    </div>
    <el-row class="device-status-wrap">
      <div v-for="item in DeviceEnum.properties" :key="item.name" class="device-status-item">
        <span class="color" :style="{backgroundColor:item.color}" /><span :style="{color:item.color}">{{ item.name }}</span>
      </div>
    </el-row>
    <div class="factory-map clearfix">
      <div v-for="g in groupList" :key="g.id" class="group">
        <div class="name">{{ g.name }}</div>
        <div class="item-wrap">

          <div v-for="equip in g.equipments" :key="equip.id" class="item-point" :title="equip.name">
            <el-popover
              placement="right"
              width="350"
              trigger="click"
            >
              <el-card class="box-card">
                <div slot="header" class="clearfix">
                  <span class="name">设备详情</span>
                  <el-button style="float: right; padding: 3px 0" type="text">查看监控</el-button>
                </div>
                <div class="text item">
                  设备编号：{{ equip.code }}
                </div>
                <div class="text item">
                  设备名称：{{ equip.name }}
                </div>
                <div class="text item">
                  设备状态：{{ DeviceEnum.getEnumName(equip.status) }}
                </div>
                <div class="text item">
                  所属厂区：{{ g.VfactoryId }}
                </div>
                <div class="text item">
                  所属车间：{{ equip.VworkshopId }}
                </div>
                <div class="text item">
                  采购时间：{{ equip.purchaseTime }}
                </div>
                <div class="text item">
                  安装时间：{{ equip.installationTime }}
                </div>
                <div class="text item">
                  设备温度：0℃
                </div>
                <div class="text item">
                  设备湿度：0℃
                </div>
                <div class="text item">
                  设备高度：0
                </div>
                <div class="text item">
                  设备宽度：0
                </div>
                <div class="text item">
                  负责人：{{ equip.VprincipalBy }}
                </div>
                <div class="text item">
                  描述：{{ equip.description }}
                </div>
              </el-card>
              <template slot="reference">
                <img class="img" :src="equip.img" alt="">
                <div class="icon-color" :style="{backgroundColor:DeviceEnum.properties[equip.status].color}" />
              </template>
            </el-popover>
          </div>

        </div>
      </div>
    </div>
  </div>
</template>

<script>
import PanelGroup from '@/components/PanelGroup/PanelGroup'
import { DeviceEnum } from '@/utils/constant'
import userMixin from '@/mixins/userMixin'

export default {
  name: 'DeviceTime',
  components: {
    PanelGroup
  },
  mixins: [userMixin],
  data() {
    return {
      activeIndex: 0,
      DeviceEnum: DeviceEnum,
      panelGroupList: [
        {
          name: '设备总数',
          icon: 'icon-shebei',
          number: 0,
          style: {
            color: '#409EFF'
          }
        },
        {
          name: '异常总数',
          icon: 'icon-yichang',
          number: 0,
          style: {
            color: '#F56C6C',
            fontSize: '60px',
            lineHeight: '50px'
          }
        },
        {
          name: '开机总数',
          icon: 'icon-kaiji1',
          number: 0,
          style: {
            color: '#67C23A'
          }
        },
        {
          name: '停机总数',
          icon: 'icon-tingji',
          number: 0,
          style: {
            color: '#909399'
          }
        }
      ],
      groupList: []
    }
  },
  created() {
    this.getFactoryList().then(() => {
      const factory = this.factoryList[0]
      this.getGroupList(factory.id)
    })
  },
  methods: {
    getGroupList(factoryId) {
      this.$api.device.getCurrentEquipments({ id: factoryId }).then(res => {
        if (res.code === this.$code) {
          this.groupList = res.data.workshops
        }
      })
    }
  }
}
</script>
<style lang="scss">
  // 卡片
  .box-card {
    width: 320px;
    .name{
      font-size: 20px;
    }
    .text {
      font-size: 16px;
    }
    .item {
      margin-bottom: 18px;
    }
  }
</style>
<style lang="scss" scoped>
  .device-time-page {
    background: #f0f2f5;
    min-height: calc(100vh - 84px);

    .display-wrap{
      text-align: center;
    }
    //状态渲染
    .device-status-wrap{
      margin-top: 10px;
      .color{
        display: inline-block;
        margin-right: 8px;
        width: 12px;
        height: 12px;
        border-radius: 50%;
      }
      .device-status-item{
        display: inline-block;
        margin-right: 20px;
      }
    }

    .factory-wrap {

      .el-button {
        margin-left: 0;
        margin-top: 10px;
        margin-right: 10px;
      }
    }
    .factory-map{
      margin-top: 30px;
      width: 100%;
      min-height: 230px;
      border:1px solid #ccc;
      padding: 10px 20px;

      .group{
        padding: 10px 10px;
        float: left;
        width: 23%;
        margin: 20px 1%;
        min-height: 200px;
        background: #fff;
        border-radius: 8px;

        .name{
          text-align: center;
          font-size: 20px;
          font-weight: bold;
        }
        .item-wrap{

          .item-point{
            cursor: pointer;
            float: left;
            width: 23%;
            margin: 8px 1%;
            text-align: center;
            min-width: 30px;
            .img{
              width: 30px;
              height: 30px;
            }
            .icon-color{
              margin: 0 auto;
              width: 10px;
              height: 10px;
              border-radius: 50%;
            }
          }
        }
      }

      @media screen and (max-width: 1200px) {
        .group{
          width: 48%;
        }
      }
    }
  }

</style>
